package edu.hunau.annotation;

import java.lang.reflect.Method;

/**
 * @author hb
 * @date 2022-11-22 11:24:51
 */
public class ProcessorTest {
    public static void process(String className) throws Exception{
        int passed=0;//成功计数器
        int failed=0; //失败计数器

        Class<?> clazz = Class.forName(className);
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            //如果该方法使用了@Testable 修饰
            if( method.isAnnotationPresent(Testable.class)){
               try {
                   method.invoke(null);
                   passed++;
               }catch (Exception e) {
                   System.out.println(method + "运行失败，异常:" + e.getCause());
                   failed++;
               }
            }
        }
        System.out.println("共运行了:" + (passed + failed) + "个方法，期中:\n" + "失败了:" + failed + "个,\n" + "成功了:" + passed + "个!");

    }
}
